<?php

    class SportObject{
        function beatBasketball($name,$height,$weight,$age,$sex){
            echo "姓名:".$name;
            echo "身高:".$height;
            echo "体重:".$weight;
        }
    }
    class SportObject1{
        function playBesketball($name,$height,$weight,$age,$sex){
            if ($height>180 and $weight<=100){
                return $name."，符合打篮球的条件";
            }else{
                return $name."，不符合打篮球的条件";
            }
        }
    }
    $sport=new SportObject1();
    echo $sport->playBesketball('小明','185','80','20','male');

    class SportObject2{
        public $name;
        public $helight;
        public $weight;

        public function playBesketball($name,$height,$weight){
            if ($height>180 and $weight<=100){
                return $name."，符合打篮球的条件";
            }else{
                return $name."，不符合打篮球的条件";
            }
        }
    }
    $sport=new SportObject2();
    echo $sport->playBesketball('imyou','185','80');

    class  SportObject3{
        const BOOK_TYPE="计算机图书";
        public $object_name;
        function setObjectName($name){
            $this->object_name;
        }
        function getObjectName(){
            return $this->object_name;
        }
    }
    $book=new SportObject3();//实例化对象
    $book->getObjectName("PHP类");
    echo SportObject3::BOOK_TYPE."->";
    echo $book->getObjectName();

    class SportObject4{
        public $name;
        public $helight;
        public $weight;
        public $age;
        public $sex;


        public function _construct($name,$height,$weight,$age,$sex)
        {
            $this->name=$name;
            $this->helight=$height;
            $this->weight=$weight;
            $this->sex=$sex;
            $this->age;
        }
        public function playBesketball(){
            if ($this->height>180 and $this->weight<=100){
                return $this->name."，符合打篮球的条件";
            }else{
                return $this->name."，不符合打篮球的条件";
            }
        }
    }
    $sport=new SportObject4('明日','185','80','20','male');
    //$sport->name='明日';
    //$sport->helight='185';
    //$sport->weight='80';
    //$sport->age='20';
    //$sport->sex='male';
    echo $sport->playBesketball();


    //析构函数，作用是在对象被销毁时调用，作用是释放内存。
    class SportObject5{
        public $name;
        public $helight;
        public $weight;
        public $age;
        public $sex;


        public function _construct($name,$height,$weight,$age,$sex)
        {
            $this->name=$name;
            $this->helight=$height;
            $this->weight=$weight;
            $this->sex=$sex;
            $this->age;
        }
        public function playBesketball(){
            if ($this->height>180 and $this->weight<=100){
                return $this->name."，符合打篮球的条件";
            }else{
                return $this->name."，不符合打篮球的条件";
            }
        }
        function _destruct(){                                   //析构函数
            echo "<p><b>对象被销毁，调用析构函数。</b>></p>>";
        }
    }
    $sport=new SportObject5('明日','185','80','20','male');
    /**
    php函数采用的是垃圾回收制机制，自动清除不再使用的对象，释放内存。
     * 也就是说不用使用unset（）函数，析构函数也会被调用，治理只是说明
     * 析构函数何时被使用。一般情况下不需要手动创建的。
     **/

    /**
    *继承和多态
     **/
    class SportObject6
    {
        public $name;

        public $weight;
        public $age;
        public $sex;


        public function _construct($name, $weight, $age, $sex)
        {
            $this->name = $name;

            $this->weight = $weight;
            $this->sex = $sex;
            $this->age=$age;
        }
        function showme(){
            echo "这句话不会被显示。";
        }
    }
    class PlayBasketBall extends SportObject6{              //定义子类，继承父类
        public $height;
        function _construct($name, $height)
        {
            $this->name=$name;
            $this->height=$height;
        }
        function showme()
        {
            if ($this->height>185){
                return $this->name."，符合打篮球的条件";
            }else{
                return $this->name.",不符合打篮球的条件";
            }
        }
    }
    class WeightLifting extends SportObject6{           //举重类
        function showme()
        {
            if ($this->weight<85){
                echo $this->name."符合举重的条件";
            }else{
                echo $this->name."不符合举重条件";
            }
        }
    }
    //实例化子类
    $Playbasketball=new PlayBasketBall('明日','190');
    $wightlifting=new WeightLifting('科技','185','80','20','male');
    echo $Playbasketball->showme()."<br>";
    echo $wightlifting->showme()."<br>";

    //多态
    abstract class car{
        abstract function getspeed();
    }
    class toyota extends car{
        function getspeed()
        {
            return "toyota speed";// TODO: Implement getspeed() method.
        }
    }
    class nissan extends car{
        function getspeed()
        {
            return"nissan speed";// TODO: Implement getspeed() method.
        }
    }
    class tesla extends car{
        function getspeed()
        {
            return"tesla speed";// TODO: Implement getspeed() method.
        }
    }
    $car=new toyota();
    $speed=$car->getspeed();
    echo $speed;
    /**
    "::"的使用
     **/
    class Book{
        const NAME="computer";
        function _construct(){
            echo '本年度图书类销售冠军为:'.Book::NAME.'<br>';
        }
    }
    class BookRank extends  Book{
        const NAME = 'foreign language';
        function _construct()
        {
            parent::_construct(); // TODO: Change the autogenerated stub  调用父类构造方法
            echo '本月图书销售冠军为：'.self::NAME.'  ';//输出本类的默认值
        }
    }
    $obj=new BookRank();//实例化对象
    $obj->_construct();
?>